<?php
	$where_cat = "";
	if(isset($_GET['var2']))
		$where_cat = " where titleurl = '".$_GET['var2']."' ";
	
	$re_cat = $db->select("select * from product_cat $where_cat  order by orderId asc, id asc limit 1 ");
	$tt_cat = $db->fetch($re_cat);
?>
<div class="w260 mr20">
	<div class="title fsize17">Danh mục</div>
	
	<ul class="pl-list">
		<?php
		$re_list = $db->select("select * from product_cat where level = 1 order by orderId asc");
		while($tt_list = $db->fetch($re_list))
		{
			if(($act=="product" || $act=="product-detail" ) && $tt_list['id'] == $tt_cat['id'])
				$subClass = "active";
			else 
				$subClass = "";
		?>
		<li class="<?= $subClass ?>">
			<a href="<?=APPLICATION_URL?>product/<?=$tt_list['titleurl']?>.html"><?=$tt_list['title'.$hg]?></a>
			<div class="clear"></div>
		</li>
		<?php
		}
		?>
		
	</ul>
</div>
<div class="w700">
	<div class="title">Sản phẩm</div>
	<ul class="pro-items">
		<?php			
		$i = 0;					
		include_once "library/paging.cls.php";
		$paging=new paging();
		$curpg = $_GET['var3'];
		$curpg=(isset($curpg))?$curpg:1;	
		$gotopage  = APPLICATION_URL."san-pham/".$tt_cat['titleurl'];					
		$perpage = 9;
		$pagecount = 10;				
		
		$where_list = " where idcat = '".$tt_cat['id']."' ";
		$sql = "select * from product_item $where_list  ";
		
		$query = $db->select($sql);	
		$totalrows=$db->numrows($query);	
		$sql_list = "select * from product_item $where_list order by orderId asc, id asc limit ".(($curpg-1)*$perpage).", ".$perpage;	
		$qr_list = $db->select($sql_list);	
		$num_list = $db->numrows($qr_list);
		if ($num_list > 0) {					
			while($tt_list = $db->fetch($qr_list))
			{ 
				$i++;
				if(($i - 1)%3 == 1)
					$margin = 'class="pro-margin"';
				else
					$margin = "";
			?>
				<li <?= $margin; ?>>
					<div class="pro-item-ctn">
						<a href="<?=APPLICATION_URL?>product-detail/<?=$tt_cat['titleurl']?>/<?=$tt_list['titleurl']?>.html"><img alt="" src="<?=APPLICATION_URL?>product-img/list/<?=$tt_list['image']?>"></a>
						<div class="name"><a href="<?=APPLICATION_URL?>product-detail/<?=$tt_cat['titleurl']?>/<?=$tt_list['titleurl']?>.html"><?=$tt_list['title'.$hg]?></a></div>
						<div class="home-right-bg"><?= formatPrice($tt_list['price']); ?></div>
					</div>
				</li>
		<?php
			}
		}else{
			if ($hg) { //Tiếng Việt
				echo 'Không có sản phẩm nào trong thể loại này';
			}else{
				echo 'No product in this category';
			}
		}
		?>
		
	</ul>
	<div class="clear"></div>
	<div class="paging"><?php echo $paging->pagenew($totalrows, $perpage, $pagecount, $curpg, $gotopage, "","titlepage");?></div>
</div>
